import wsgiref.handlers
from google.appengine.ext import webapp

import Timegine

class Demo( webapp.RequestHandler ):

  def get( self ):
    self.response.headers['Content-Type'] = 'text/html'

    zones = Timegine.obtain_zones()
    option_str = ''
    for z in zones:
      option_str += '<option value="%(value)s">%(abbr)s - %(full)s</option>\n' % {
          'value'   : z[2]
        , 'abbr'    : z[0]
        , 'full'    : z[1]
      }


    self.response.out.write(
      r'''
      <h3>Yet Another Time Converter</h3>
      <form action="/time-converter/convert" method="GET">

      Date - <input id="date" name ="date" type="text" />(dd/mm/yyyy)
      Time - <input id="time" name="time" type="text"  />(hh:mm)

      <br/>
      <br/>

      From -
      <select id="from-zone" name="from-zone">
      %(options)s
      </select>

      <br/>
      <br/>

      To -
      <select id="to-zone" name="to-zone">
      %(options)s
      </select>

      <br/>
      <br/>

      <button type="submit">Convert!</button>

      </form>

      <a href="http://appengine.google.com/"><img
      src="http://code.google.com/appengine/images/appengine-silver-120x30.gif"
      alt="Powered by Google App Engine" style="border:none;" /></a>

      <script type="text/javascript" language="javascript">
      var d = new Date();
      var date = ( ( d.getDate() > 9 )? '' : '0' ) + d.getDate();
      var month = ( ( d.getMonth() + 1 > 9 )? '' : '0' ) + (d.getMonth() + 1);
      var year = d.getFullYear();
      var hour = ( ( d.getHours() > 9 )? '' : '0' ) + d.getHours();
      var minute = ( ( d.getMinutes() > 9 )? '' : '0' ) + d.getMinutes();

      document.getElementById("date").value = date + '/' + month + '/' + year;
      document.getElementById("time").value = hour + ':' + minute;
      </script>
      ''' % {
          'options' : option_str
      }
    )
  # end of Demo.get

# end of class Demo
